import {Component} from '@angular/core';
import {NavigationEnd, Router, RouterOutlet} from "@angular/router";
import {HeaderComponent} from "../../components/header/header.component";
import {FooterComponent} from "../../components/footer/footer.component";
import {slideInAnimation} from "../../animations/animations";

@Component({
  selector: 'app-main',
  standalone: true,
  imports: [
    RouterOutlet,
    HeaderComponent,
    FooterComponent
  ],
  templateUrl: './main.component.html',
  styleUrl: './main.component.scss',
  animations: [slideInAnimation],
})
export class MainComponent {
  constructor(private router: Router) {
  }

  ngOnInit() {
    this.router.events.subscribe((event: any) => {
      if (event instanceof NavigationEnd) {
        window.scrollTo({
          top: 0,
          left: 0,
          behavior: 'instant' // 平滑滚动
        });
      }
    })
  }

  prepareRoute(outlet: RouterOutlet) {
    return outlet && outlet.activatedRouteData //&& outlet.activatedRouteData['animation'];
  }
}
